home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Module: erase.c - Bulk eraser for floppy disks */
- /* */
- /* Programmer: George R. Woodside */
- /* */
- /* Date: February 7, 1987 */
- /* */
- /* Function: Fast erase of a floppy disk by re-writing FATs */
- /* and directory. */
- /* */
- /****************************************************************************/
-
- #include <stdio.h>
- #include <osbind.h>
-
- long stuff[128 * 17]; /* data buffer */
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- register int i = 0; /* confirmation flag */
- register int drive; /* drive to erase */
- register char *look; /* look at command arguments */
- register long reply; /* O/S response */
-
- if(argc < 2) /* if no arguments, */
- {
- printf("Erase: Complete erasure of a floppy disk.\n");
- printf("Usage: erase [ab] [y]\n");/* print usage */
- exit(1); /* and exit */
- } /* end not enough arguments */
-
- if( (*argv[1] == 'a') || (*argv[1] == 'A') )
- drive = 0; /* remember drive */
-
- if( (*argv[1] == 'b') || (*argv[1] == 'B') )
- drive = 1; /* remember drive */
-
- if(argc > 2)
- {
- if( (*argv[2] == 'y') || (*argv[2] == 'Y') )
- i = 1; /* show pre-confirmed */
- }
-
- if( (argc > 2) && (i == 0) ) /* if not confirmed, */
- {
- look = argv[2]; /* get the second argument */
- if(*look++ == '-' ) /* if a leading hyphen, */
- {
- if( (*look == 'y') || (*look == 'Y') ) /* then a yes, */
- i = 1; /* show pre-confirmed */
- } /* end hyphenated yes */
- } /* end not confirmed with 2 args */
-
- if(i == 0) /* if not confirmed yet, */
- {
- printf("Erase floppy drive %c, confirm with 'y':",drive + 'a');
- i = Cconin(); /* read a character */
- if( (i != 'y') && (i != 'Y') ) /* if not a y, */
- exit(1); /* punt */
- } /* end not confirmed */
-
- for(i = 0; i < 17 * 128; i++) /* 17 sectors, longs are quicker */
- stuff[i] = 0L; /* fill the buffer with zeroes */
-
- stuff[0] = 0xf7ffff00L; /* set up first FAT */
- stuff[640] = 0xf7ffff00L; /* set up second FAT */
-
- Getbpb(drive); /* insure the drive is known */
- reply = Rwabs(1,stuff,17,1,drive); /* write the buffer */
-
- if(reply == 0L) /* if no problems on write, */
- {
- Rwabs(0,0L,2,0,drive); /* set media has changed */
- exit(0); /* did it OK */
- } /* end successful erasure */
-
- printf("Error code %D\n",reply); /* log error */
- exit(1); /* exit as error */
- }
-